package org.lanqiao.component;

import com.alibaba.fastjson.JSONObject;
import org.lanqiao.mapper.ActivityMapper;
import org.lanqiao.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import java.util.Map;


@Component
public class Listener {



    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    private ActivityMapper activityMapper;

    @JmsListener(destination = StringUtil.activity_query_queue)
    public void receiveActivity(String text){
//        System.out.println("receiveActivity: 活动消费者 收到一条信息: " + text);
//        //消费者将活动数据存进redis
//        redisTemplate.opsForValue().set(StringUtil.all_activity,text);
    }

    @JmsListener(destination = StringUtil.gift_query_queue)
    public void receiveGift(String text){
//        Map map = JSONObject.parseObject(text);
//        redisTemplate.opsForValue().set(StringUtil.all_gift.concat(map.get("wxId").toString()),map.get("data").toString());
    }

    @JmsListener(destination = StringUtil.gift_query_queue_user)
    public void receiveGiftUser(String text){
//        Map map = JSONObject.parseObject(text);
//        redisTemplate.opsForValue().set(StringUtil.gift_user.concat(map.get("wxId").toString()).concat("#").concat(map.get("activityId").toString()),map.get("data").toString());
    }

    @JmsListener(destination = StringUtil.activity_queue)
    public void receive(String text){
//        System.out.println("QueueListener: 活动状态修改消费者 收到一条信息: " + text);
//        //更新redis的对应活动记录，此处一次性更新所有,将记录存进redis覆盖，也可更新单条
//        redisTemplate.opsForValue().set(StringUtil.all_activity,activityMapper.getAllActivity());
    }

    @JmsListener(destination = StringUtil.activity_gift)
    public void receiveActivityGift(String text){
//        System.out.println("QueueListener: 活动礼物消费者 收到一条信息: " + text);
//        redisTemplate.opsForValue().set(StringUtil.activity_gift,text);
    }

    @JmsListener(destination = StringUtil.records)
    public void receiveRecords(String text){
//        System.out.println("QueueListener: 充值消费者 收到一条信息: " + text);
//        Map map = JSONObject.parseObject(text);
//        redisTemplate.opsForValue().set(StringUtil.records.concat(map.get("wxId").toString()),map.get("data").toString());
    }
}
